<script setup>


import {ref, watchEffect} from "vue";

let count = ref(0);
let count2 = ref(0);

//1:定义停止监听
const stop = watchEffect(()=>{
  console.log(count.value)
},{
  flush:'post'
})

setTimeout(()=>{
  //2：停止监听
  stop();
},1000)

setTimeout(()=>{
  count.value +=1 ;
},2000)

//3：提供一个形参，主要清除上一次的行为
watchEffect((cb)=>{
  console.log(count2.value)
  cb(()=>{
    //更新前和卸载前触发
    console.log('before update')
  })
},{
  flush:'post'
})

setTimeout(()=>{
  count2.value +=1 ;
},2000)


</script>

<template>
  <div ref="elem">06_composition_api_watch_watcheffect_02.vue
    {{count}}，{{count2}}
  </div>
</template>

<style scoped>

</style>